/**
 * 
 */
package chml;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;

import org.omg.CORBA.PUBLIC_MEMBER;

/**
 * @author chengmenglong
 *
 */
public class TestAccuracy {

	public static String getAccuracy(String filename, int common){
		
		int count = 0;
		int correctCount = 0;
		File resultFile = new File(filename);
		if(!resultFile.exists())
	    { 
	        System.err.println("Can't Find " + filename);
		}
		
		try 
		{
		    BufferedReader in = new BufferedReader(new FileReader(resultFile));
		    String qstr;
		    while ((qstr = in.readLine()) != null) 
		    {
		    	String dstr = in.readLine();
		    	count++;
		    	String [] qStrings = qstr.split(" ");
		    	String [] dStrings = dstr.split(" ");
		    	if(getWindowCommon(qStrings, dStrings) >= common){
		    		correctCount++;
		    	}
		    }
		    in.close();
		} 
		catch (IOException e) 
		{
		    e.getStackTrace();
		}
		return count + " " + correctCount;
	}
	
	//获取两个window的差异量
	public static int getWindowCommon(String[] docWindow, String[] queryWindow){
		int common = 0;
		
		String[] docCopy = Arrays.copyOf(docWindow, docWindow.length);
		String[] queryCopy = Arrays.copyOf(queryWindow, queryWindow.length);
		
		for(String query: queryCopy){
			for(int i = 0; i < docCopy.length; i++){
				String doc = docCopy[i];
				if(query.equals(doc)){
					docCopy[i] = null;
					common++;
					break;
				}
			}
		}
		
		return common;
	}
	
}
